#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 50 + 10;

int t, n;

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    cin >> t;
    while(t--) {
        cin >> n;
        ll minn = 1e9 + 1, maxx = -1;
        ll a;
        for (int i = 0; i < n; i++) {
            cin >> a;
            minn = min(minn, a);
            maxx = max(maxx, a);
        }
        cout << maxx - minn << endl;
    }
    return 0;
}